home *** CD-ROM | disk | FTP | other *** search
/ Univers Interactif 3 / INTERACTIF.BIN / pc / planeten / internet / machttp2.sit / MacHTTP 2.0 / MacHTTP Software & Docs / Tutorials / Examples / map.script < prev    next >
Text File  |  1994-12-18  |  3KB  |  64 lines

  1. --this script should be compiled and saved as an application before running
  2. --
  3. -- Variables available for use:
  4. -- http_search_args - stuff in the URL after a ?
  5. -- path_args - stuff in the URL after a $
  6. -- post_args - stuff sent from forms, etc. when POST method is used
  7. -- method - GET, POST, etc. Used to tell if post_args are valid
  8. -- client_address - IP address or domain name of remote client's host
  9. -- from_user - non-standard. e-mail address of remote user
  10. -- username - authenticated user name
  11. -- password - authenticated password
  12. -- server_name - name or IP address of this server
  13. -- server_port - TCP/IP port number being used by this server
  14. -- script_name - URL name of this script
  15. -- referer - the URL of the page referencing this document
  16. -- user_agent - the name and version of the WWW client software being used
  17. -- content_type - MIME content type of post_args
  18.  
  19. property crlf : (ASCII character 13) & (ASCII character 10)
  20.  
  21. --this builds the normal HTTP header for regular access
  22. property http_10_header : "HTTP/1.0 200 OK" & crlf & "Server: MacHTTP" & crlf & ┬
  23.     "MIME-Version: 1.0" & crlf & "Content-type: text/html" & crlf & crlf
  24.  
  25. --this builds the redirect HTTP header for regular access
  26. property redirect_header : "HTTP/1.0 302 Found" & crlf & "Server: MacHTTP" & crlf & ┬
  27.     "MIME-Version: 1.0" & crlf & "Location: http://"
  28.  
  29. --stuff a simple HTML document in this property
  30. property body_text : "<title>Map Demo</title><h1>Map Demo</h1>" & ┬
  31.     "<a href=map.cgi><img src=map.gif ismap></a><p>Click Me!<p>"
  32.  
  33.  
  34. try --wrap the whole script in an error handler
  35.     
  36.     -- http_search_args variable will contain the click coordinates.
  37.     -- if they're blank, let's return a simple HTML document to prompt the user.
  38.     if http_search_args = "" then
  39.         return http_10_header & body_text
  40.     else
  41.         -- otherwise, extract the x and y coordinates from this variable
  42.         set AppleScript's text item delimiters to ","
  43.         set x to (text item 1 of http_search_args) as integer
  44.         set y to (text item 2 of http_search_args) as integer
  45.         
  46.         -- Now figure out where we clicked
  47.         if x < 36 and y < 36 then
  48.             set answer_text to "You clicked ONE."
  49.             return http_10_header & body_text & "You clicked ONE. x=" & x & " y=" & y
  50.         else if x < 72 and y < 36 then
  51.             return http_10_header & body_text & "You clicked TWO. x=" & x & " y=" & y
  52.         else if y < 36 then
  53.             return http_10_header & body_text & "You clicked THREE. x=" & x & " y=" & y
  54.         else
  55.             --build a redirect message, using this host's name, etc.
  56.             -- and return the MacHTTP icon in the Images folder. Note the 2 trailing crlf's
  57.             return redirect_header & server_name & ":" & server_port & "/Images/MacHTTP.gif" & crlf & crlf
  58.         end if
  59.     end if
  60.     
  61. on error msg number num --report the error message and number to the WWW client
  62.     return http_10_header & "Error " & num & ", " & msg
  63. end try
  64.